﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EzDesk.Project.Model;
using EzDesk.Project.Service.Repositories.Interfaces;

namespace EzDesk.Project.Service.Repositories.Mock
{
    public class Mock_ProjectBasicInfoRepository: Mock_Repository<ProjectBasicInfo>, IProjectBasictInfoRepository
    {
        public Guid TestProjectId1 = new Guid("80CB7E0F-1B4E-428C-92D9-DED7D943AFE8");
        public Guid TestProjectTeamId1 = new Guid("E27306CB-FC1E-42D9-9020-5B453B7D3752");

        public Guid TestProjectId2 = new Guid("8B544374-105E-454D-900A-E389A9DA37EB");
        public Guid TestProjectTeamId2 = new Guid("E74D2241-0917-45D7-8C95-602502DFA834");

        public Mock_ProjectBasicInfoRepository()
        {
            Initialize();
        }

        protected override void Initialize()
        {
            if (!HasInitialized)
            {
                innerManager.ClearAll();

                innerManager.Add(
                    new ProjectBasicInfo()
                    {
                        Id = TestProjectId1,
                        ProjectName = "测试项目一",
                        ProjectNo = "MIC-003-2009",
                        CreateOn = DateTime.Parse("2009/4/3"),
                        Creator = innerManager.ApiClient.GetSimpleUserById(innerManager.SampleUsers["杨裕欣"]),
                        IsCloesd = false,
                        Remark = "简单的备注",
                        ProjectType = ProjectTypeEnum.建筑,
                        ProjectTeamId = TestProjectTeamId1,
                    }
                , true
                );

                innerManager.Add(
                    new ProjectBasicInfo()
                    {
                        Id = TestProjectId2,
                        ProjectName = "测试项目二",
                        ProjectNo = "TEST-002-2010",
                        CreateOn = DateTime.Parse("2009/5/3"),
                        Creator = innerManager.ApiClient.GetSimpleUserById(innerManager.SampleUsers["杨裕欣"]),
                        IsCloesd = false,
                        Remark = "简单的备注 二",
                        ProjectType = ProjectTypeEnum.景观,
                        ProjectTeamId = TestProjectTeamId2,
                    }
                , true
                );
            }

            base.Initialize();
        }

        public IList<ProjectBasicInfo> GetProjectList(bool? isClosed, string orderBy)
        {
            var result = innerManager.GetAll();
            if (isClosed.HasValue)
            {
                result = result.Where(p => p.IsCloesd == isClosed);
            }
            if (orderBy == "CreateOn")
            {
                result = result.OrderBy(p => p.CreateOn);
            }
            return result.ToList();
        }
    }
}
